package cn.xuyang520.tyim.test.controller;

import cn.xuyang520.tyim.sys.domain.TySysUser;
import cn.xuyang520.tyim.sys.domain.TySysUserRepository;

import cn.xuyang520.tyim.sys.core.TyCache;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by admin on 2017/4/1.
 */
@RestController
@RequestMapping("/test")
public class TyTestController {
    @Autowired
    RedisTemplate<String, TySysUser> redisTemplate;
    @Autowired
    TySysUserRepository tySysUserRepository;


    @Autowired
    TyCache tyCache;

    @RequestMapping
    public Object test() {
        //SecurityContextHolder.clearContext();
        ValueOperations<String, TySysUser> value = redisTemplate.opsForValue();
        TySysUser a = value.get("a");
        System.out.println(value);

        //redisTemplate.value
        //stringRedisTemplate.op

        tySysUserRepository.findOne("1");

        TySysUser user = tySysUserRepository.findByTbUsernameAndTbPassword("admin","admin");

        System.out.print(user);

        //SecurityManager securityManager = SecurityUtils.getSecurityManager();
        Subject subject = SecurityUtils.getSubject();
        System.out.println("什么时候校验？");
        System.out.println(subject.hasRole("admin"));

        System.out.println(subject.isPermitted("permissions"));

        tyCache.set("a", "b", "c");


        if (a == null)
            a = new TySysUser();
        a.setTbId("111111111");

        tyCache.set("abc", a);
        System.out.println(tyCache.get("abc"));
        value.set("a", a);
        return value.get("a");
    }



}
